var QuanLyBanHangStatic = {
    baseURL:  'http://' + window.location.host + '/QuanLyBanHang/',

    addElementToOverlay : function(obj){
        obj = $(obj);
        var overlay = $('#overlay-content-content');
        overlay.html('');
        obj.appendTo(overlay);
    },

    toggleOverlay : function(show){
        if (show){
            $('#overlay').fadeIn(100);
            setTimeout(function(){
                $('#overlay #overlay-content').show("drop", {direction: "up"}, 200);
            }, 100);
        }
        else{
            $('#overlay #overlay-content').hide("drop", {direction: "up"}, 200);
            setTimeout(function(){
                $('#overlay').fadeOut(100);
            },200);
        }
    },

    setOverlaySize : function(width, height){
        var div = $('#overlay #overlay-content');
        if (width > 680)
            width = 680;
        div.css('width', width);
        div.css('height', height);
    },

    changeMessage : function(title, content, icon){
        if (icon == undefined)
            icon = 'fa-warning';
        var container = $('#popup-content');
        container.find('.popup-title').html(title);
        container.find('.message-icon .fa').removeClass().addClass('fa').addClass(icon);
        container.find('.popup-content-content').html(content);
    },

    showMessageBox : function (autohide, delay){
        if (delay == undefined){
            delay = '';
        }

        var messageBox = $('#popup-message');
        if (autohide){
            messageBox.fadeIn(300);
            setTimeout(function(){
                messageBox.fadeOut(300);
            }, delay);
        } else{
            messageBox.fadeIn(300);
        }
    },

    hideMessageBox : function(){
        $('#popup-message').fadeOut(300);
    },

    preventEvent : function(e){
        e.stopPropagation();
    },

    changeURLWithoutReload : function(link){
        window.history.pushState("object or string", "Title", this.baseURL + link);
    },

    checkNumberInput: function(e){
        if (e.charCode > 57 || e.charCode < 46){
            e.preventDefault();
            return;
        }
    },
    numberWithCommas: function(x) {
        var str = x.toString().replace(/\,/g, "");
        return str.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
};

$(document).unbind('keydown').bind('keydown', function (event) {
    var doPrevent = false;
    if (event.keyCode === 8) {
        var d = event.srcElement || event.target;
        if ((d.tagName.toUpperCase() === 'INPUT' &&
            (
                d.type.toUpperCase() === 'TEXT' ||
                    d.type.toUpperCase() === 'PASSWORD' ||
                    d.type.toUpperCase() === 'FILE' ||
                    d.type.toUpperCase() === 'EMAIL' ||
                    d.type.toUpperCase() === 'SEARCH' ||
                    d.type.toUpperCase() === 'DATE' )
            ) ||
            d.tagName.toUpperCase() === 'TEXTAREA') {
            doPrevent = d.readOnly || d.disabled;
        }
        else {
            doPrevent = true;
        }
    }

    if (doPrevent) {
        event.preventDefault();
    }
});

